<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>websocket test</title>
</head>
<body>
<input type="text" id="pl" />
<input type="button" value="发送" id="submit" />
<input type="button" value="关闭" id="close" />
</body>
<script type="text/javascript">
    var CreateWebSocket = (function () {
        return function (urlValue) {
            if (window.WebSocket) return new WebSocket(urlValue);
            if (window.MozWebSocket) return new MozWebSocket(urlValue);
            return false;
        }
    })();
    var webSocket = CreateWebSocket("ws://127.0.0.1:3000");
    webSocket.onopen = function (evt) {
        webSocket.send("第一条数据")
    };
    webSocket.onmessage = function (evt) {
        console.log("服务端说" + evt.data)
    };
    webSocket.onclose = function (evt) {
        console.log("Connection closed.")
    };
    document.getElementById("submit").onclick = function () {
        var str = document.getElementById("pl").value;
        webSocket.send(str)
    }
</script>
</html>
